package cn.lbaicai.core;

import org.apache.shiro.SecurityUtils;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import cn.lbaicai.common.CurrentUser;

public class CurrentUserArgumentResolver implements HandlerMethodArgumentResolver {

	public boolean supportsParameter(MethodParameter parameter) {
		// TODO Auto-generated method stub
		
		return parameter.hasParameterAnnotation(CurrentUser.class);
	}

	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
		// TODO Auto-generated method stub
		CurrentUser cuser = parameter.getParameterAnnotation(CurrentUser.class);
		return SecurityUtils.getSubject().getSession().getAttribute(cuser.Currentuser());
	}

}
